#include<iostream>
#include<algorithm>

using namespace std;
#define int long long
const int N = 5e4 + 10;
int n;
struct node
{
    int w;
    int s;
}a[N];

bool cmp(node &i , node &j)
{
    return max(-i.s,i.w - j.s) < max(-j.s , j.w - i.s);
}
signed main()
{
    cin >> n;
    for(int i = 1;i <= n;i ++) cin >> a[i].w >> a[i].s;
    sort(a + 1 , a + 1 + n , cmp);
    int ret = -1e9 - 10 , w = 0;
    for(int i = 1;i <= n;i ++)
    {
        ret = max(ret , w - a[i].s);
        w += a[i].w;
    }
    cout << ret << endl;
    return 0;
}